package com.ktjy.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktjy.pojo.B2cOrder;
import com.ktjy.service.B2cOrderService;
import com.ktjy.mapper.B2cOrderMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
*
*/
@Service
public class B2cOrderServiceImpl extends ServiceImpl<B2cOrderMapper, B2cOrder>
implements B2cOrderService{
    @Resource
    RedisTemplate redisTemplate;

    @Resource
    B2cOrderMapper b2cOrderMapper;


    /**
     * 如果redis中存在则返回，否则查询数据库
     * @return
     */
    @Override
    public List<B2cOrder> getList() {

        //1、从缓存中获取数据
       List resultList= (List) redisTemplate.opsForValue().get("orderList");
       //2、如果没有获取到数据则从数据库查询并写入缓存
       if(resultList==null){
           resultList= list();
           redisTemplate.opsForValue().set("orderList",resultList);
       }

        return resultList;
    }

    @Override
    @Cacheable(value = "b2cOrderList")
    public List<B2cOrder> getOrderList() {
        return list();
    }
}
